package com.icss.controller;

import com.icss.dao.ICartDao;
import com.icss.entity.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CartController {
    @Autowired
    private ICartDao iCartDao;

    @RequestMapping("GoodAddCar")
    public String CartFun01(String userid, String goodsid, String price, HttpSession session, HttpServletResponse response){
        System.out.println("userid:"+userid+"---goodsid:"+goodsid+"--price:"+price);

        int userid01 =  Integer.parseInt(userid);
        int goodsid01 = Integer.parseInt(goodsid);
        iCartDao.GoodAddCar(userid01,goodsid01,price);
        return "forward:FindCarAll";
    }
    @RequestMapping("FindCarAll")
    public String CartFun02(int userid, HttpSession session){
        System.out.println("userid:"+userid);
        List<Cart> carts= iCartDao.FindCarAll(userid);
        System.out.println(carts);
        session.setAttribute("carts",carts);
        return "shopcar";
    }

}
